/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.core.service.processor.freeze;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.account.core.service.processor.base.AbstractAccountServiceProcessor;
import info.peigen.hotpot.business.account.facade.enums.AccountStatus;
import info.peigen.hotpot.business.account.facade.order.freeze.UnfreezeAccountOrder;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(UnfreezeAccountProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/5/26
 */
@Component
public class UnfreezeAccountProcessor extends AbstractAccountServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 20;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        UnfreezeAccountOrder order   = (UnfreezeAccountOrder) serviceContext.getOrder();
        Account              account = (Account) serviceContext.getDomain();
        Assert.notNull(account);
        account.setStatus(AccountStatus.Normal);
        memo(account, order);
        serviceContext.getResult().setSuccessNotFee();
    }

    private void memo(Account account, UnfreezeAccountOrder order) {
        String memo = "";
        if (StrUtil.isNotEmpty(order.getBopsOperatorId())) {
            memo = "[" + order.getBopsOperatorId() + "]因为[" + order.getReason() + "]解冻";
        }
        memo = "因为[" + order.getReason() + "]解冻";
        account.setMemo(memo);
    }
}
